package com.zhsm.fuxi.mvp.ui.adapter

import com.chad.library.adapter.base.BaseQuickAdapter
import com.chad.library.adapter.base.BaseViewHolder
import com.zhsm.fuxi.R
import com.zhsm.fuxi.app.Constant
import com.zhsm.fuxi.bean.OrderInfo
import com.zhsm.fuxi.utils.TimeUtils


/**
 * Created by GuZhC on 2018/11/7.
 * describe:
 */
class OederCenterRecyclerAdapter(data: List<OrderInfo>) : BaseQuickAdapter<OrderInfo, BaseViewHolder>(R.layout.layout_order_center, data) {
    override fun convert(helper: BaseViewHolder, data: OrderInfo) {
        if (data.state == Constant.ORDER.EXECUTING) {
            helper.setGone(R.id.orderStateText, true)
            helper.setTextColor(R.id.orderStateText, mContext.resources.getColor(R.color.text_orange))
            helper.setText(R.id.orderStateText, "未完成订单")
            helper.setTextColor(R.id.orderState, mContext.resources.getColor(R.color.text_orange))
            when (data.node) {
                Constant.CarState.TAKE_REPORT_SURFACE,
                Constant.CarState.TO_TAKE_VEHICLE ->
                    helper.setText(R.id.orderState, "待取车")
                Constant.CarState.TAKE_REPORT_INTERIOR,
                Constant.CarState.RETURN_REPORT_SURFACE,
                Constant.CarState.TO_RETURN_VEHICLE ->
                    helper.setText(R.id.orderState, "用车中")
                Constant.CarState.TO_BE_PAID ->
                    helper.setText(R.id.orderState, "待支付")
            }
        } else {
            if (data.isShowTop!!) {
                helper.setGone(R.id.orderStateText, true)
                helper.setTextColor(R.id.orderStateText, mContext.resources.getColor(R.color.text_hint))
                helper.setText(R.id.orderStateText, "已完成订单")
            } else helper.setGone(R.id.orderStateText, false)
            if (data.state == Constant.ORDER.CANCELLED) {
                helper.setTextColor(R.id.orderState, mContext.resources.getColor(R.color.text_black_light))
                helper.setText(R.id.orderState, "已取消")
            } else if (data.state == Constant.ORDER.COMPLETED){
                helper.setTextColor(R.id.orderState, mContext.resources.getColor(R.color.text_black))
                helper.setText(R.id.orderState, "¥${data.amount}")
            }
        }

        val startTime = TimeUtils.getTime(data.createTime!!, TimeUtils.DATE_SIMPLE_DATA)
        var endTime = ""
        data.updateTime?.let {
            if (data.updateTime > 0)
                endTime = "—${TimeUtils.getTime(it, TimeUtils.DATE_SIMPLE_DATA)}"
        }
        helper.setText(R.id.orderTime, startTime + endTime)
        helper.setText(R.id.orderStart, data.takeStation)
        if (!data.returnStation.isNullOrBlank())
            helper.setText(R.id.orderEnd, data.returnStation)
        else helper.setGone(R.id.orderEnd, false)
    }
}